<template>
  <page-header-wrapper :title="false">
    <a-card title="ISO客户列表">
      <a-tabs v-model="tab" type="card" @change="onTab">
        <a-tab-pane key="1" tab="已成单"></a-tab-pane>
        <a-tab-pane key="2" tab="未成单"></a-tab-pane>
      </a-tabs>
      <div class="table-page-search-wrapper">
        <a-form-model :model="queryParam" layout="inline">
          <a-row :gutter="48">
            <template v-if="advanced">
              <a-col :md="6" :sm="24">
                <a-form-model-item label="客户姓名">
                  <a-input v-model="queryParam['filter[customer_name]']" placeholder="输入客户姓名"/>
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-model-item label="联系电话">
                  <a-input v-model="queryParam['filter[phone]']" placeholder="输入联系电话"/>
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-model-item label="标记类型">
                  <a-select v-model="queryParam['filter[status]']" placeholder="请选择标记类型">
                    <a-select-option v-for="(item,index) in statusOpts" :key="index" :value="index">{{ item }}</a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
            </template>
            <a-col :md="!advanced && 8 || 24" :sm="24">
              <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="reset">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
      <div class="table-operator">
        <s-table
          v-show="tab == '1'"
          ref="table1"
          bordered
          :row-key="(record) => record.customer_id"
          :columns="customerColumns"
          :data="isoData"
        >
          <template slot="tm_name" slot-scope="text, record">
            {{ record.pt_name }}{{ text }}
          </template>
          <template slot="phone" slot-scope="text, record">
            {{ text }} <a-icon type="phone" theme="filled" :style="record.is_hot == 0 ? { color: '#1890ff', cursor: 'pointer' } : { color: '#ff0000', cursor: 'pointer' }" @click="makePhone(record.customer_id, record.is_hot)" />
          </template>
          <template slot="amounts"slot-scope="text">
            <a-tag color="red" v-text="text"></a-tag>
          </template>
          <template slot="action" slot-scope="text, record">
            <!--            <a-button size="small" type="primary" style="margin-right:8px;" @click="$router.push({ name: 'PaidDetail', params: {id: record.customer_id} })">查看</a-button>-->
            <a-button size="small" type="primary" style="margin-right:8px;" @click="add(record.customer_id)">做合同</a-button>
            <!--            <a-dropdown>-->
            <!--              <a-menu slot="overlay">-->
            <!--                <a-menu-item key="1"> 全部合同 </a-menu-item>-->
            <!--                <a-menu-item key="2"> 全部业务 </a-menu-item>-->
            <!--              </a-menu>-->
            <!--              <a-button type="primary" size="small"> 更多 <a-icon type="down" /> </a-button>-->
            <!--            </a-dropdown>-->
          </template>
        </s-table>
        <s-table
          v-show="tab == '2'"
          ref="table2"
          bordered
          :row-key="(record) => record.customer_id"
          :columns="customerColumns"
          :data="notData"
        >
          <template slot="tm_name" slot-scope="text, record">
            {{ record.pt_name }}{{ text }}
          </template>
          <template slot="phone" slot-scope="text, record">
            {{ text }} <a-icon type="phone" theme="filled" :style="record.is_hot == 0 ? { color: '#1890ff', cursor: 'pointer' } : { color: '#ff0000', cursor: 'pointer' }" @click="makePhone(record.customer_id, record.is_hot)" />
          </template>
          <template slot="amounts"slot-scope="text">
            <a-tag color="red" v-text="text"></a-tag>
          </template>
          <template slot="action" slot-scope="text, record">
            <!--            <a-button size="small" type="primary" style="margin-right:8px;" @click="$router.push({ name: 'PaidDetail', params: {id: record.customer_id} })">查看</a-button>-->
            <a-button size="small" type="primary" style="margin-right:8px;" @click="add(record.customer_id)">做合同</a-button>
            <!--            <a-dropdown>-->
            <!--              <a-menu slot="overlay">-->
            <!--                <a-menu-item key="1"> 全部合同 </a-menu-item>-->
            <!--                <a-menu-item key="2"> 全部业务 </a-menu-item>-->
            <!--              </a-menu>-->
            <!--              <a-button type="primary" size="small"> 更多 <a-icon type="down" /> </a-button>-->
            <!--            </a-dropdown>-->
          </template>
        </s-table>
      </div>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
import { getIso, getNotIso } from '@/api/customer'
import col from '@/columns/customer'
const customerColumns = col.other2

export default {
  components: {
    STable
  },
  name: 'IsoCustomer',
  data () {
    return {
      customerColumns,
      isoData: parameters => {
        return getIso(Object.assign(parameters, this.queryParam)).then(res => {
          this.statusOpts = res.result.customer_status_opts
          return res.result
        })
      },
      notData: parameters => {
        return getNotIso(Object.assign(parameters, this.queryParam)).then(res => {
          this.statusOpts = res.result.customer_status_opts
          return res.result
        })
      },
      advanced: true,
      queryParam: {},
      modalVisible: false,
      tab: '1',
      customerId: '',
      statusOpts: {}
    }
  },
  methods: {
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    onTab (key) {
      this.$refs.table1.refresh(true)
      this.$refs.table2.refresh(true)
    },
    reset () {
      this.queryParam = {}
      this.$refs.table1.refresh(true)
      this.$refs.table2.refresh(true)
    },
    add (id) {
      this.$router.push({ name: 'AddContract', query: { customer_id: id } })
    }
  }
}
</script>

<style scoped>

</style>
